<template>
<div class="layerRtb layerRtb-threecolumn">
    <three-title :title="{name:'项经罚款'}"></three-title>
    <div class="layerRtb-scroll thinScroll" v-scrollHeight = "137">
        <div class="analyItem">
            <p class="analyItemTit tx-center">项目</p>
            <div class="analyItemCon">
                <p class="col-md-4">
                    <span class="cLightGray pr8">单号</span>
                    <span>{{leftInfo.orderno}}</span>
                </p>
                <p class="col-md-8">
                    <span class="cLightGray pr8">项目名称</span>
                    <span>{{leftInfo.proname}}</span>
                </p>
            </div>
        </div>
        <div class="analyItem">
            <p class="analyItemTit tx-center">罚单</p>
            <div class="analyItemCon">
                <p class="col-md-6">
                    <span class="cLightGray pr8 fl">罚款类型</span>
                    <el-select v-model="typeValue" placeholder="请选择类型" @change="typeChange()" class="fl" style="width: 150px">
                        <el-option
                            size="mini"
                            v-for="item in typeOptions"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id">
                        </el-option>
                    </el-select>
                </p>
                <p class="col-md-6">
                    <span class="cLightGray pr8 fl">罚款科目</span>
                    <el-select v-model="projectValue" placeholder="请选择科目" @change="projectChange()"  class="fl"  style="width: 150px">
                        <el-option
                            size="mini"
                            v-for="item in projectOptions"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id">
                        </el-option>
                    </el-select>
                </p>
                <p class="col-md-6 mt10">
                    <span class="cLightGray pr8 fl">罚款等级</span>
                    <el-select v-model="gradeValue" placeholder="请选择等级" @change="GradeChange()"  class="fl" style="width: 150px">
                        <el-option
                            size="mini"
                            v-for="item in gradeList"
                            :key="item.id"
                            :label="item.gradeLabel"
                            :value="item.id">
                        </el-option>
                    </el-select>
                </p>
                <p class="col-md-6 mt10">
                    <span class="cLightGray pr8 fl">罚款金额</span>
                    <span>{{currentGrade === null ? '' : currentGrade.fine}}</span>
                    <!-- <el-input v-model="moneyInput" placeholder="请输入罚款金额" size="mini" class="fl" type="number" style="width:200px"></el-input> -->
                </p>
                 <p class="col-md-12 mt10">
                    <span class="cLightGray pr8 fl">问题描述</span>
                    <textarea v-model="fineTextDec" placeholder="请描述内容" class="col-md-10"></textarea>
                </p>
                <div class="col-md-12 mt10">
                    <span class="cLightGray pr8 fl">图片上传</span>
                    <rx-upload
                        class="fl"
                        :data="{id: 11}" :init="{class: 7, mime: 1}"
                        :elStyle="{width:'90px', height: '80px'}"
                        @success="successUpload">
                        <div class="fl uiImgUpload uiImgUpload-gblock mr10">
                            <a href="javascript:">
                                <span type="file" value="" class="file"></span>
                                <em class="bgIcon file-ico"></em>
                            </a>
                        </div>
                    </rx-upload>
                    <rx-viewer v-for="(item, index) of fineList" :key="index" class="mr10 fl">
                        <div class="look_imgHover fl relative" style="width:78px;height:78px;" >
                             <img :src="item">
                            <div class="upload_finish_div">
                                <div class="upload_finish_bg"></div>
                                <div class="upload_finish_linksm">
                                    <div class="dis-il-block">
                                        <a href="javascript:" class="ImgBtn enlarge_viewer enlarge_link" :data-src="item"></a>
                                        <a href="javascript:" class="ImgBtn delect_link" @click="delectImg(index)"></a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </rx-viewer>
                </div>
            </div>
        </div>
    </div>
    <div class="layerRtb-footer">
        <div class="analyItem">
            <p class="analyItemTit tx-center">综合</p>
            <div class="analyItemCon">
                <div class="tx-center">
                    <input type="button" class="uiBtn-normal uiBtn-blue" value="确定" @click="addFineMoneyByUid()">
                </div>
            </div>
        </div>
    </div>
</div>
</template>
<script>
import { mapGetters } from 'vuex'
import { addFineMoneyByUid, saveSiteFine, getFirstType, getChildStandard, getFineStandardById } from '../Resources/Api/index'
export default {
    data () {
        return {
            typeOptions: [], // 类型数组
            projectOptions: [], // 科目数组
            typeValue: '', // 类型Value
            projectValue: '', // 科目Value
            gradeValue: '', // 等级Value
            currentGrade: null, // 当前等级的Value
            gradeList: [], // 等级List
            fineList: [], // 罚款图片
            // moneyInput: '', // 罚款金额
            fineTextDec: '' // 罚款描述
        }
    },
    computed: {
        ...mapGetters(['leftInfo', 'userInfo'])
    },
    created () {
        this.getFirstType()
    },
    methods: {
        // 路由跳转路径拼接
        routerPath (path) {
            return this.$route.matched[1].path + '/' + path
        },
        // 直接进行路由跳转路径
        routerPush (path) {
            this.$router.push(this.$route.matched[1].path + '/' + path)
        },
        // 图片上传
        successUpload (value) {
            this.fineList.push(value.src)
        },
        // 图片删除
        delectImg (index) {
            this.fineList.splice(index, 1)
        },
        // 排序
        compare (prop) {
            return function (a, b) {
                return a[prop] - b[prop]
            }
        },
        // 获取类型列表
        getFirstType () {
            getFirstType().then(results => {
                if (results.data.StatusCode === 1) {
                    this.typeOptions = []
                    this.typeOptions = results.data.Body.firstTypeList
                }
            }).catch(error => {
                console.log(error)
            })
        },
        // 类型改变获取科目
        typeChange () {
            let parms = {
                id: Number(this.typeValue)
            }
            getChildStandard(parms).then(results => {
                if (results.data.StatusCode === 1) {
                    this.projectOptions = []
                    this.projectOptions = results.data.Body.standardList
                    this.gradeList = []
                    this.projectValue = ''
                    this.gradeValue = ''
                }
            }).catch(error => {
                console.log(error)
            })
        },
        // 科目改变获取等级
        projectChange () {
            let parms = {
                id: Number(this.projectValue)
            }
            getFineStandardById(parms).then(results => {
                if (results.data.StatusCode === 1) {
                    this.gradeList = []
                    this.gradeValue = ''
                    this.gradeList = results.data.Body.standardList
                    this.gradeList = this.gradeList.sort(this.compare('grade'))
                    this.gradeList.forEach(item => {
                        switch (Number(item.grade)) {
                        case 1:
                            this.$set(item, 'gradeLabel', '等级一')
                            break
                        case 2:
                            this.$set(item, 'gradeLabel', '等级二')
                            break
                        case 3:
                            this.$set(item, 'gradeLabel', '等级三')
                            break
                        default:
                            break
                        }
                    })
                }
            }).catch(error => {
                console.log(error)
            })
        },
        // 等级改变获取罚款
        GradeChange () {
            const currentGrade = this.gradeList.filter((item) => { return item.id === Number(this.gradeValue) })
            if (currentGrade.length > 0) {
                this.currentGrade = currentGrade[0]
                this.fineTextDec = this.currentGrade.remark
            }
        },
        // 提交罚款
        addFineMoneyByUid () {
            if (this.fineTextDec === '') {
                this.$message('输入问题描述')
                return false
            }
            let parm = {
                uid: this.leftInfo.pm_uid,
                userName: this.leftInfo.pm_username,
                founderCard: this.userInfo.as_cardNo,
                founderName: '客户',
                orderNo: this.leftInfo.orderno,
                orderProName: this.leftInfo.proname,
                fineMoney: this.currentGrade === null ? 0 : this.currentGrade.fine,
                fineRemark: this.fineTextDec,
                finePicture: this.fineList.length > 0 ? this.fineList.join(',') : '',
                fineSubject: 12,
                fineType: 4,
                dqId: this.leftInfo.areaid,
                fineStage: 1,
                userCardNo: '',
                contractNo: '',
                DivisionId: '',
                CorpsId: '',
                SourceType: '',
                SubjectA: '',
                SubjectB: ''
            }
            addFineMoneyByUid(parm).then((result) => {
                if (result.data.statusCode === 1) {
                    this.fineList = [] // 罚款图片
                    // this.moneyInput = '' // 罚款金额
                    this.fineTextDec = '' // 罚款描述
                    this.typeValue = '' // 类型Value
                    this.projectValue = '' // 科目Value
                    this.gradeValue = '' // 等级Value
                    this.currentGrade = null
                    // 调用闫传强的接口 保存罚款记录
                    parm.standard_id = Number(this.gradeValue)
                    saveSiteFine(parm).then((result) => {
                        if (result.data.count > 0) {
                            console.log('保存日志成功')
                        }
                    }).catch((error) => {
                        console.log(error)
                    })
                    this.$message('罚款成功')
                } else {
                    this.$message(result.data.statusMsg)
                }
            }).catch((error) => {
                console.log(error)
            })
        }
    }
}
</script>
